/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package de.hbrs.ooka.crs.servlet;

import de.hbrs.ooka.beans.UserSessionStatefulLocal;
import de.hbrs.ooka.entities.UserEntity;
import de.hbrs.ooka.enums.Role;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public abstract class AbstractViewServlet extends HttpServlet {

    protected UserSessionStatefulLocal getCrsBean(HttpServletRequest request) {
        HttpSession userSession = request.getSession(false);
        if (userSession == null) {
            return null;
        }
        return (UserSessionStatefulLocal) userSession.getAttribute("crsbean");
    }
    
    protected boolean isUserAuthenticated(UserEntity user, Role requiredRole){
        if(user == null){
            return false;
        } else{
            if(user.getRoles().contains(requiredRole)){
                return true;
            }
        }
        return false;
    }
}
